package com.qf.modules.sys.controller;

import com.qf.common.persistence.Page;
import com.qf.common.util.ResultInfo;
import com.qf.modules.sys.entity.Menu;
import com.qf.modules.sys.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @RequestMapping("getListData")
    public ResultInfo getListData(HttpServletRequest request){
        Menu menu = new Menu();
        String parentId = request.getParameter("parentId");
        menu.setParentId(parentId);
        List<Menu> menuList = menuService.findList(menu);
        return ResultInfo.ok().setData(menuList);
    }

    @RequestMapping("getPageData")
    public ResultInfo getPageData(Menu menu, HttpServletRequest request){
        Page<Menu> page = menuService.findPage(new Page<>(), menu);
        return ResultInfo.ok().setData(page);
    }

    @RequestMapping("save")
    public ResultInfo save(@RequestBody Menu menu){
        menuService.save(menu);
        return ResultInfo.ok();
    }

    @RequestMapping("delete")
    public ResultInfo delete(HttpServletRequest request){
        String id = request.getParameter("id");
        menuService.delete(id);
        return ResultInfo.ok();
    }
}
